#include "messagePageStyle.h"
#include "ui_messagePageStyle.h"
#include "globaldata.h"
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
#include <QtNetwork/QNetworkRequest>
#include <QDesktopWidget>
#include <QSettings>
#include <QApplication>
#include <QDebug>
#include <QMessageBox>

/* 适配组内SDK */
#include <ukuistylehelper/ukuistylehelper.h>
#include "windowmanage.hpp"

MessagePageStyle::MessagePageStyle(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MessagePageStyle),
    m_hasDetailText(false),
    m_isMailFormat(false)
{
    this->setWindowTitle("message_page");

    ui->setupUi(this);
    uiInit();
    getSysteminfo();

    m_eMail = new SmtpMailClient();
    m_pMailThread = new QThread();
    m_eMail->moveToThread(m_pMailThread);
    connect(m_pMailThread, &QThread::finished, m_eMail, &QObject::deleteLater);//挂载
    connect(this,&MessagePageStyle::connectToHost, m_eMail,&SmtpMailClient::connectToHost);
    connect(m_eMail,&SmtpMailClient::hostConnectResult,this,&MessagePageStyle::mailHostConnectResult);
    connect(this,&MessagePageStyle::sendMail, m_eMail,&SmtpMailClient::sendMail);
    connect(m_eMail,&SmtpMailClient::mailSendResult,this,&MessagePageStyle::mailSendResult);
    qRegisterMetaType<mailContent>("mailContent");
    m_pMailThread->start();

    this->show();
}

MessagePageStyle::~MessagePageStyle()
{
    delete ui;
    if (m_waitDialog)
    {
        delete m_waitDialog;
        m_waitDialog = nullptr;
    }
    if (m_successDialog)
    {
        delete m_successDialog;
        m_successDialog = nullptr;
    }

    if (m_failDialog)
    {
        delete m_failDialog;
        m_failDialog = nullptr;
    }

    m_pMailThread->quit();
    if(!m_pMailThread->wait(3000))
    {
        m_pMailThread->terminate();
        m_pMailThread->wait();
    }
    m_pMailThread->deleteLater();
}
void MessagePageStyle::uiInit()
{
    pageStyleOfAskRowLocationInit();
    pageContentOfAskRowLocationInit();
    pageUploadFilesRowLocationInit();
    pageSysLogRowLocationInit();
    pageMailRowLocationInit();
    pageTelRowLocationInit();
    pageSysInfoLocationInit();

    m_waitDialog = new SubmitBase;
    m_waitDialog->setLabelMovie();
    m_waitDialog->setLabelText(tr("Submitting..."));
    m_waitDialog->setModal(true);
    /* 适配kysdk的窗管 */
    kdk::UkuiStyleHelper::self()->removeHeader(m_waitDialog);

    m_successDialog = new SubmitBase();
    m_successDialog->setLabelPix("border-image:url(:/data/finish.png);border:0px;");
    m_successDialog->setLabelText(tr("Submit Successed!"));
    m_successDialog->hide();
    kdk::UkuiStyleHelper::self()->removeHeader(m_successDialog);

    m_failDialog = new SubmitBase();
    m_failDialog->setLabelPix("border-image:url(:/data/fail.png);border:0px;");
    m_failDialog->hide();
    /* 适配kysdk的窗管 */
    kdk::UkuiStyleHelper::self()->removeHeader(m_failDialog);
}
void MessagePageStyle::pageStyleOfAskRowLocationInit()
{
    ui->m_pStyleOfAsk->setText(tr("Question*"));//"咨询类别 *");
    ui->m_pStyleOfAsk->setAlignment(Qt::AlignLeft);
    ui->m_pStyleOfAsk->setAlignment(Qt::AlignVCenter);

    ui->m_pStyleOfAskCombobox->addItem((tr("System")));//("系统问题")));
    ui->m_pStyleOfAskCombobox->addItem((tr("Suggestion")));//("意见建议")));
    ui->m_pStyleOfAskCombobox->addItem((tr("Bussiness")));//("商务合作")));
    ui->m_pStyleOfAskCombobox->addItem((tr("Others")));//"其他")));
    connect(ui->m_pStyleOfAskCombobox,SIGNAL(currentIndexChanged(QString)),this,SLOT(styleOfAskCombobox_currentIndexChanged(QString)));
}
void MessagePageStyle::pageContentOfAskRowLocationInit()
{
    ui->m_pTitleOfAsk->setText(tr("Content"));//"咨询内容 *");
    ui->m_pTitleOfAsk->setAlignment(Qt::AlignLeft);
    ui->m_pTitleOfAsk->setAlignment(Qt::AlignVCenter);

    ui->m_pContentTextEdit->setObjectName("ContentTextEdit");
    ui->m_pContentTextEdit->setAlignment(Qt::AlignLeft|Qt::AlignTop);
    ui->m_pContentTextEdit->setAcceptRichText(false);

    connect(ui->m_pContentTextEdit,SIGNAL(textChanged()),this,SLOT(detailTextEdit_textChanged()));

    ui->m_pDetailTextLetterLimit->setText(tr("Word Limit"));//"已达到字符上限");
    ui->m_pDetailTextLetterLimit->setObjectName("DetailTextLetterLimit");
    ui->m_pDetailTextLetterLimit->setStyleSheet("QLabel#DetailTextLetterLimit{color:rgba(245, 108, 108, 1);}");
    ui->m_pDetailTextLetterLimit->setAlignment(Qt::AlignLeft);
    ui->m_pDetailTextLetterLimit->setAlignment(Qt::AlignVCenter);
    ui->m_pDetailTextLetterLimit->hide();
}

/************************************************
* 函数名称：pageUploadFilesRowLocationInit
* 功能描述：上传文件行初始化
* 输入参数：无
* 输出参数：无
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*
*************************************************/
void MessagePageStyle::pageUploadFilesRowLocationInit()
{
    ui->m_pUserData->setText(tr("Upload"));//"上传附件");
    ui->m_pUserData->setAlignment(Qt::AlignLeft);
    ui->m_pUserData->setAlignment(Qt::AlignVCenter);

    ui->m_pUserDataPushButton->setObjectName("m_pUserDataPushButton");

    ui->m_pUserDataPushButton->setText(tr("Browse"));//("浏览"));
    ui->m_pUserDataPushButton->setProperty("isImportant", true);

    connect(ui->m_pUserDataPushButton,SIGNAL(clicked()),this,SLOT(userDataPushButton_clicked()));

    ui->m_pUserDataLimit->setText(tr("All attachmens size should smaller than 10MB and numbers less than 5"));//("总附件大小不超过10mb，附件数量不超过5个"));
    ui->m_pUserDataLimit_2->setText(tr("Support format:.gif *.jpg *.png *.pptx *.wps *.xlsx *.pdf *.txt *.docx"));//("总附件大小不超过10mb，附件数量不超过5个"));

    ui->m_pUserDataLimit->setStyleSheet("background-color:transparent;color:rgba(140, 140, 140, 1) ;");
    ui->m_pUserDataLimit_2->setStyleSheet("background-color:transparent;color:rgba(140, 140, 140, 1) ;");
}

/************************************************
* 函数名称：pageSysLogRowLocationInit
* 功能描述：系统日志行初始化
* 输入参数：无
* 输出参数：无
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*
*************************************************/
void MessagePageStyle::pageSysLogRowLocationInit()
{
    ui->m_pLog->adjustSize();
    ui->m_pLog->setText(tr("UploadLog"));//"上传日志");
    ui->m_pLog->setAlignment(Qt::AlignLeft);
    ui->m_pLog->setAlignment(Qt::AlignVCenter);

    ui->m_pTrueSyslogRadioButton->setChecked(true);
    connect(ui->m_pTrueSyslogRadioButton,SIGNAL(toggled(bool)),this,SLOT(syslogUpload_stateChanged()));

    ui->m_pFalseSyslogRadioButton->setText(tr("No"));//"否"));
}

/************************************************
* 函数名称：pageMailRowLocationInit
* 功能描述：留邮箱行初始化
* 输入参数：无
* 输出参数：无
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*
*************************************************/
void MessagePageStyle::pageMailRowLocationInit()
{
    ui->m_pMail->setText(tr("Mail"));//"邮件 *");
    ui->m_pMail->setAlignment(Qt::AlignLeft);
    ui->m_pMail->setAlignment(Qt::AlignVCenter);

    ui->m_pMailTextEdit->setObjectName("MailTextEdit");

    ui->m_pMailTextEdit->setAlignment(Qt::AlignVCenter);
    QString placeHolder = tr("Leave your E-mail to get response");
    ui->m_pMailTextEdit->setPlaceholderText(placeHolder);//("KylinOS服务与支持团队将通过您预留的邮件反馈处理进度和结果"));
    ui->m_pMailTextEdit->setEchoModeBtnVisible(false);
    connect(ui->m_pMailTextEdit,SIGNAL(textChanged(QString)),this,SLOT(mailTextEdit_textChanged()));
    connect(ui->m_pMailTextEdit, SIGNAL(editingFinished()), this, SLOT(mailTextEditFoucusOut()));

    ui->m_pMailFormatErr->setText(tr("Incorrect E-mail address."));//"邮箱格式不正确");
    ui->m_pMailFormatErr->setAlignment(Qt::AlignLeft);
    ui->m_pMailFormatErr->setAlignment(Qt::AlignVCenter);
    ui->m_pMailFormatErr->hide();
    ui->m_pMailTextEdit->setState(kdk::Ordinary);
    ui->m_pMailTextEdit->setEchoMode(QLineEdit::Normal);
}

/************************************************
* 函数名称：pageTelRowLocationInit
* 功能描述：留电话行初始化
* 输入参数：无
* 输出参数：无
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*
*************************************************/
void MessagePageStyle::pageTelRowLocationInit()
{
    ui->m_pTel->setText(tr("Tel"));//"电话");
    ui->m_pTel->setAlignment(Qt::AlignLeft);
    ui->m_pTel->setAlignment(Qt::AlignVCenter);

    ui->m_pTelTextEdit->setObjectName("TelTextEdit");

    ui->m_pTelTextEdit->setMaxLength(25);
    ui->m_pTelTextEdit->setAlignment(Qt::AlignVCenter);
//    ui->m_pTelTextEdit->setPlaceholderText(tr("Leave your Tel to get response."));//("用于反馈处理进度和结果的联系电话"));
    connect(ui->m_pTelTextEdit,SIGNAL(textChanged(QString)),this,SLOT(telTextEdit_textChanged()));

    ui->m_pName->setText(tr("Name"));//"称谓");
    ui->m_pName->setAlignment(Qt::AlignLeft);
    ui->m_pName->setAlignment(Qt::AlignVCenter);

    ui->m_pNameTextEdit->setObjectName("NameTextEdit");

    ui->m_pNameTextEdit->setMaxLength(15);
    ui->m_pNameTextEdit->setAlignment(Qt::AlignVCenter);
//    ui->m_pNameTextEdit->setPlaceholderText(tr("What should I call you."));//("联系人姓名"));
    connect(ui->m_pNameTextEdit,SIGNAL(textChanged(QString)),this,SLOT(nameTextEdit_textChanged()));
}
void MessagePageStyle::pageSysInfoLocationInit()
{
    //获取系统信息的小弹窗
    m_verticalWidget = new QWidget(this);
    m_verticalWidget->setObjectName(QString::fromUtf8("verticalWidget"));

    m_verticalWidget->setAutoFillBackground(true);
    m_verticalWidget->setBackgroundRole(QPalette::Button);
    m_verticalWidget->hide();

    m_labelSystemVersion_1 = new QLabel(m_verticalWidget);
    m_labelSystemVersion_1->setObjectName(QString::fromUtf8("labelSystemVersion1"));
    m_labelSystemVersion_1->setText(tr("Os_rel")+tr(":"));


    m_labelSystemVersion_2 = new QLabel(m_verticalWidget);
    m_labelSystemVersion_2->setAlignment(Qt::AlignLeft);
    m_labelSystemVersion_2->setObjectName(QString::fromUtf8("labelSystemVersion2"));

    m_labelDesktopVersion_1 = new QLabel(m_verticalWidget);
    m_labelDesktopVersion_1->setObjectName(QString::fromUtf8("labelDesktopVersion1"));
    m_labelDesktopVersion_1->setText(tr("Deskenv")+tr(":"));

    m_labelDesktopVersion_2 = new QLabel(m_verticalWidget);
    m_labelDesktopVersion_2->setAlignment(Qt::AlignLeft);
    m_labelDesktopVersion_2->setObjectName(QString::fromUtf8("labelDesktopVersion2"));

    m_labelLanguage_1 = new QLabel(m_verticalWidget);
    m_labelLanguage_1->setText(tr("Lang")+tr(":"));
    m_labelLanguage_1->setObjectName(QString::fromUtf8("labelLanguage1"));

    m_labelLanguage_2 = new QLabel(m_verticalWidget);
    m_labelLanguage_2->setAlignment(Qt::AlignLeft);
    m_labelLanguage_2->setObjectName(QString::fromUtf8("labelLanguage2"));

    QVBoxLayout *verticalWidgetLayout = new QVBoxLayout(m_verticalWidget);
    QHBoxLayout *lineFirst = new QHBoxLayout();
    lineFirst->setMargin(0);
    lineFirst->setSpacing(0);
    lineFirst->addSpacing(8);
    lineFirst->addWidget(m_labelSystemVersion_1);
    lineFirst->addSpacing(8);
    lineFirst->addWidget(m_labelSystemVersion_2);
    lineFirst->addStretch();
    lineFirst->addSpacing(8);
    QHBoxLayout *lineSecond = new QHBoxLayout();
    lineSecond->setMargin(0);
    lineSecond->setSpacing(0);
    lineSecond->addSpacing(8);
    lineSecond->addWidget(m_labelDesktopVersion_1);
    lineSecond->addSpacing(8);
    lineSecond->addWidget(m_labelDesktopVersion_2);
    lineSecond->addStretch();
    lineSecond->addSpacing(8);
    QHBoxLayout *lineThird = new QHBoxLayout();
    lineThird->setMargin(0);
    lineThird->setSpacing(0);
    lineThird->addSpacing(8);
    lineThird->addWidget(m_labelLanguage_1);
    lineThird->addSpacing(8);
    lineThird->addWidget(m_labelLanguage_2);
    lineThird->addStretch();
    lineThird->addSpacing(8);

    verticalWidgetLayout->setContentsMargins(8,8,8,8);
    verticalWidgetLayout->setSpacing(0);
    verticalWidgetLayout->addLayout(lineFirst);
    verticalWidgetLayout->addSpacing(4);
    verticalWidgetLayout->addLayout(lineSecond);
    verticalWidgetLayout->addSpacing(4);
    verticalWidgetLayout->addLayout(lineThird);

    m_verticalWidget->setLayout(verticalWidgetLayout);

    ui->FileListWidget->hide();

    m_submittingTimer = new QTimer(this);
    m_submittingTimer->setInterval(30000);
    connect(m_submittingTimer,&QTimer::timeout,this,[=](){

        m_submittingTimer->stop();
        //set_all_enable_after_submit();

    });
    ui->commitButton->setEnabled(false);

    ui->m_pUserPermission->setText(tr("Upload my "));//"同意获取我的"));
    ui->m_pUserPermission->setObjectName(QString::fromUtf8("checkBox"));
    ui->m_pUserPermission->setChecked(true);//默认勾选上传本机信息
    connect(ui->m_pUserPermission,SIGNAL(stateChanged(int)),this,SLOT(userPermission_stateChanged(int)));

    ui->m_showInfoButton->setText(tr("System Info"));//"系统信息"));
    ui->m_showInfoButton->setFeedBack(this);
    ui->m_showInfoButton->setEnabled(false);

    QGSettings *m_gsetting = nullptr;

    if (QGSettings::isSchemaInstalled(THEME_GSETTINGS)) {
        /* 主题 */
        m_gsetting = new QGSettings(THEME_GSETTINGS, QByteArray(), this);
        m_colorName = m_gsetting->get(THEME_HIGH_COLOR).toString();
        connect(m_gsetting, &QGSettings::changed, this, [=]() {
            if (m_colorName != m_gsetting->get(THEME_HIGH_COLOR).toString()) {
                m_colorName = m_gsetting->get(THEME_HIGH_COLOR).toString();
                QColor highLightColor = QApplication::palette().highlight().color();
                QString highLightStr = QString("#%1%2%3").arg(highLightColor.red(), 2, 16,QChar('0'))
                                                .arg(highLightColor.green(), 2, 16,QChar('0'))
                                                .arg(highLightColor.blue(), 2, 16,QChar('0'));
                QString str = QString("QCheckBox{background-color:transparent;color:%1;}QCheckBox::indicator{width:0px;height:0px;}")
                              .arg(highLightStr);
                ui->m_showInfoButton->setStyleSheet(str);
                this->update();
            }
        });
    }

    //TODO:新版高亮协议
    ui->commitButton->setProperty("isImportant", true);
    ui->commitButton->setObjectName("commitButton");
    ui->commitButton->setText(tr("Commit"));//"提交"));
    connect(ui->commitButton,SIGNAL(released()),this,SLOT(commitButtonPressed()),Qt::UniqueConnection);

    ui->resetButton->setProperty("useButtonPalette", true);
    ui->resetButton->setObjectName("resetButton");
    ui->resetButton->setText(tr("Reset"));//"重置"));
    ui->resetButton->setEnabled(true);
    connect(ui->resetButton,SIGNAL(clicked()),this,SLOT(on_resetButton_clicked()));
}
/************************************************
* 函数名称：styleOfAskCombobox_currentIndexChanged
* 功能描述：问题类别combobox值变化槽函数
* 输入参数：无
* 输出参数：无
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*
*************************************************/
void MessagePageStyle::styleOfAskCombobox_currentIndexChanged(QString str)
{
    m_textStyleOfAsk = str;
}

/************************************************
* 函数名称：detailTextEdit_textChanged
* 功能描述：问题详细描述文本框文字变化
* 输入参数：无
* 输出参数：无
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*
*************************************************/
void MessagePageStyle::detailTextEdit_textChanged()
{
    if( "" == ui->m_pContentTextEdit->toPlainText())
    {
        m_hasDetailText = false;
        ui->m_pDetailTextLetterLimit->hide();
    }
    else
    {
        m_hasDetailText = true;
        m_detailText = ui->m_pContentTextEdit->toPlainText();

        int length = m_detailText.count();
        int maxLength = 200;
        if (length > maxLength) {
            QTextCursor cursor = ui->m_pContentTextEdit->textCursor();
            cursor.movePosition(QTextCursor::End);
            if (cursor.hasSelection()) {
                cursor.clearSelection();
            }
            cursor.deletePreviousChar();
            //设置当前的光标为更改后的光标
            //Set the current cursor to the changed cursor
            ui->m_pContentTextEdit->setTextCursor(cursor);
        }
        length = ui->m_pContentTextEdit->toPlainText().count();

        if(length == 200)
        {
            ui->m_pDetailTextLetterLimit->show();
        }
        else
        {
            ui->m_pDetailTextLetterLimit->hide();
        }
    }

    commitButtonStyleSet();
}

/************************************************
* 函数名称：on_commitButton_clicked
* 功能描述：提交按钮点击槽函数
* 输入参数：无
* 输出参数：无
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*
*************************************************/
void MessagePageStyle::commitButtonPressed()
{
    if(m_submittingTimer->isActive())
    {
        QString warningMsg = tr("You Can Submit 1 time per 30s!");
        QMessageBox Msg(QMessageBox::Warning,tr("Tips:"),warningMsg,QMessageBox::Yes);
        Msg.button(QMessageBox::Yes)->setText(tr("Yes"));
        Msg.exec();
        return;
    }
    if(false == commitButtonStyleSet())
    {
        return;
    }
    //TODO:  57152 【服务与支持】留言咨询时提示“无服务序列号”，建议去掉这个限制

    LocalInfo m;
    m.getLocalInfo();
    m.getHandledLocalInfo();
    if(m.getHandledLocalInfo().serviceKey == "kyinfo文件不存在" || m.getHandledLocalInfo().serviceKey == "未读取到客户服务序列号")
    {
        qWarning() << "用户无服务序列号！";
    }

    m_messageStruct.askTitle = m_textStyleOfAsk;
    m_messageStruct.customerEMail = m_mailText;
    m_messageStruct.questionDescription = m_detailText;
    if(!m_nameText.isEmpty())
    {
        m_messageStruct.customerName = m_nameText;
    }
    else
    {
        m_messageStruct.customerName = "未填写";
    }

    if(!m_telText.isEmpty())
    {
        m_messageStruct.customerTel = m_telText;
    }
    else
    {
        m_messageStruct.customerTel = "未填写";
    }

    if (m_hasGotSystemInfo)
    {
        m_messageStruct.OSVersion = m_sendOsInfo;
        m_messageStruct.desktopVersion = m_sendDekstopInfo;
        m_messageStruct.systemLanguage = m_sendEncodingInfo;
    }
    else
    {
        m_messageStruct.OSVersion = "";
        m_messageStruct.desktopVersion = "";
        m_messageStruct.systemLanguage = "";
    }

    if(m_uploadFilePathList.size())
    {
        m_messageStruct.fileList.clear();
        m_messageStruct.fileList.append(m_uploadFilePathList);
    }
    else
    {
        m_messageStruct.fileList.clear();
    }
    if (m_hasGotSyslog == 1)
    {
        /* sdk功能打点：文件拷贝 */
        GlobalData::SDKPointFileCopy();

        m_messageStruct.fileList.append("/var/log/syslog");
        m_messageStruct.fileList.append("/var/log/kern.log");
        m_messageStruct.fileList.append("/var/log/dpkg.log");
        m_messageStruct.fileList.append("/var/log/Xorg.0.log");
        m_messageStruct.fileList.append("/var/log/dmesg");
        m_messageStruct.fileList.append("/var/log/apport.log");
    }
    else
    {
        m_messageStruct.fileList.clear();
    }

    m_waitDialog->setModal(true);

    QPoint temp = QPoint(this->mapToGlobal(QPoint(0,0)).x() -90 + this->width()/2,this->mapToGlobal(QPoint(0,0)).y() + this->height()/2 -40);
    m_waitDialog->move(temp - m_waitDialog->rect().center());
    m_waitDialog->show();

    set_all_disable_in_submit();

    emit connectToHost();
}
/************************************************
* 函数名称：set_all_enable_after_submitt
* 功能描述：提交完成后功能还原
* 输入参数：无
* 输出参数：无
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*
*************************************************/
void MessagePageStyle::set_all_enable_after_submit()
{
    ui->m_pContentTextEdit->setEnabled(true);
    ui->m_pMailTextEdit->setEnabled(true);
    ui->m_pTelTextEdit->setEnabled(true);
    ui->m_pNameTextEdit->setEnabled(true);
    ui->m_pTrueSyslogRadioButton->setEnabled(true);
    ui->m_pFalseSyslogRadioButton->setEnabled(true);
    ui->m_pUserPermission->setEnabled(true);

    ui->m_pUserDataPushButton->setEnabled(true);
    ui->resetButton->setEnabled(true);

    for (int filenum = 0; filenum< m_uploadFileNameList.size();filenum++)
    {
        m_fileWidget[filenum]->setDelBtn(true);
    }

    commitButtonStyleSet();
}
/************************************************
* 函数名称：set_all_disable_in_submit
* 功能描述：提交过程中禁止操作
* 输入参数：无
* 输出参数：无
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*
*************************************************/
void MessagePageStyle::set_all_disable_in_submit()
{
    ui->m_pContentTextEdit->setEnabled(false);
    ui->m_pMailTextEdit->setEnabled(false);
    ui->m_pTelTextEdit->setEnabled(false);
    ui->m_pNameTextEdit->setEnabled(false);
    ui->m_pTrueSyslogRadioButton->setEnabled(false);
    ui->m_pFalseSyslogRadioButton->setEnabled(false);
    ui->m_pUserPermission->setEnabled(false);
    ui->resetButton->setEnabled(false);
    ui->m_pUserDataPushButton->setEnabled(false);

    commitButtonStyleSet();

    for (int filenum = 0; filenum < m_uploadFileNameList.size(); filenum++)
        m_fileWidget[filenum]->setDelBtn(false);
}

/************************************************
* 函数名称：on_resetButton_clicked
* 功能描述：重置按钮点击槽函数
* 输入参数：无
* 输出参数：无
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*
*************************************************/
void MessagePageStyle::on_resetButton_clicked()
{
    ui->m_pStyleOfAskCombobox->setCurrentText(tr("System"));

    ui->m_pContentTextEdit->clear();
    ui->m_pMailTextEdit->clear();
    ui->m_pMailTextEdit->setState(kdk::Ordinary);
    ui->m_pMailFormatErr->hide();
    ui->m_pNameTextEdit->clear();
    ui->m_pTelTextEdit->clear();
    m_hasGotSyslog = 1;
    ui->m_pTrueSyslogRadioButton->setChecked(true);
    ui->m_pFalseSyslogRadioButton->setChecked(false);
    ui->m_pUserPermission->setChecked(true);//默认勾选上传本机信息
    ui->m_pUserDataPushButton->setEnabled(true);
    //清空list
    for (int i = 0; i < m_uploadFileNameList.size(); i++) {
        delete m_fileListWidgetItem[i];
        delete m_fileWidget[i];
    }
    foreach (auto item, m_uploadFileNameList) {
        m_uploadFileNameList.removeOne(item);
    }
    foreach (auto item,m_uploadFileSizeList) {
        m_uploadFileSizeList.removeOne(item);
    }
    foreach(auto item,m_uploadFilePathList) {
        m_uploadFilePathList.removeOne(item);
    }
    //隐藏页面上的附件列表
    ui->FileListWidget->hide();
    commitButtonStyleSet();
}

/************************************************
* 函数名称：commitButtonStyleSet
* 功能描述：commitButton样式修改函数
* 输入参数：无
* 输出参数：无
* 修改日期：2020.12.19
* 修改内容：
*   创建  HZH
*
*************************************************/
bool MessagePageStyle::commitButtonStyleSet()
{
    if((false == allFileSizeLargerThan10M()) && m_hasDetailText && m_isMailFormat)
    {
        ui->commitButton->setEnabled(true);
        return true;
    }
    else
    {
        ui->commitButton->setEnabled(false);
        return false;
    }
}

/************************************************
* 函数名称：mailTextEdit_textChanged
* 功能描述：邮件地址文本框文字变化
* 输入参数：无
* 输出参数：无
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*
*************************************************/
void MessagePageStyle::mailTextEdit_textChanged()
{
    if("" == ui->m_pMailTextEdit->text())// || (!m_pMailTextEdit->toPlainText().contains("@")))
    {
        m_isMailFormat = false;
    }
    else if(!ui->m_pMailTextEdit->text().contains("@"))
    {
        ui->m_pMailFormatErr->hide();
        ui->m_pMailTextEdit->setState(kdk::Ordinary);
        m_isMailFormat = false;

    }
    else if(false == m_isMailFormat)
    {
        m_mailText = ui->m_pMailTextEdit->text();

        QRegExp rx("^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+");
        int pos=0;
        QRegExpValidator v(rx, 0);
        if (2==v.validate(m_mailText,pos))
        {
            ui->m_pMailFormatErr->hide();
            ui->m_pMailTextEdit->setState(kdk::Ordinary);
            m_isMailFormat = true;
        }
    }
    else
    {
        m_mailText = ui->m_pMailTextEdit->text();

        QRegExp rx("^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+");
        int pos=0;
        QRegExpValidator v(rx, 0);
        if (2!=v.validate(m_mailText,pos))
        {
            ui->m_pMailFormatErr->show();
            ui->m_pMailTextEdit->setState(kdk::LoginFailed);
            m_isMailFormat = false;

        }

    }

    commitButtonStyleSet();
}

/************************************************
* 函数名称：allFileSizeLargerThan10M
* 功能描述：添加的文件总大小是否大于10M
* 输入参数：无
* 输出参数：无
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*
*************************************************/
bool MessagePageStyle::allFileSizeLargerThan10M()
{
    qint64 allFilesize = 0;
    QFileInfo fileInfo;
    for (int filenum = 0; filenum < m_uploadFilePathList.size(); filenum++) {
        fileInfo.setFile(m_uploadFilePathList.at(filenum));
        allFilesize += fileInfo.size();
    }

    if (allFilesize > 10*1024*1024)
    {
        qDebug() << "所有文件大小超限制" << allFilesize/(1024) << "KB" <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__;
        ui->m_pUserDataLimit->setStyleSheet("background-color:transparent;color:rgba(245, 108, 108, 1);");
        ui->m_pUserDataLimit_2->setStyleSheet("background-color:transparent;color:rgba(245, 108, 108, 1);");
        return true;
    }
    else
    {
        ui->m_pUserDataLimit->setStyleSheet("background-color:transparent;color:rgba(140, 140, 140, 1) ;");
        ui->m_pUserDataLimit_2->setStyleSheet("background-color:transparent;color:rgba(140, 140, 140, 1) ;");
        return false;
    }
}

/************************************************
* 函数名称：telTextEdit_textChanged
* 功能描述：联系电话文本框文字变化
* 输入参数：无
* 输出参数：无
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*
*************************************************/
void MessagePageStyle::telTextEdit_textChanged()
{
    if("" == ui->m_pTelTextEdit->text())// || (!m_pMailTextEdit->toPlainText().contains("@")))
    {
        m_isTelFormat = false;
    }
    else if(false == m_isTelFormat)
    {
        m_telText = ui->m_pTelTextEdit->text();
    }
}
/************************************************
* 函数名称：telTextEdit_textChanged
* 功能描述：联系电话文本框文字变化
* 输入参数：无
* 输出参数：无
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*
*************************************************/
void MessagePageStyle::nameTextEdit_textChanged()
{
    m_nameText = ui->m_pNameTextEdit->text();
}
/************************************************
* 函数名称：trueSyslogCheckBox_stateChanged
* 功能描述：是否允许上传系统日志checkbox改变，是否互锁
* 输入参数：无
* 输出参数：无
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*
*************************************************/
void MessagePageStyle::syslogUpload_stateChanged()
{
    if (ui->m_pTrueSyslogRadioButton->isChecked() == true)
    {
        m_hasGotSyslog = 1;
    }
    else if (ui->m_pTrueSyslogRadioButton->isChecked() == false)
    {
        m_hasGotSyslog = 0;
    }
}

/************************************************
* 函数名称：userPermission_stateChanged
* 功能描述：用户是否允许上传本地信息
* 输入参数：无
* 输出参数：无
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*
*************************************************/
void MessagePageStyle::userPermission_stateChanged(int state)
{
    if (state == Qt::Checked)
    {
        m_hasGotSystemInfo = 1;
    }
    else
    {
        m_hasGotSystemInfo = 0;
    }
    return;
}
/************************************************
* 函数名称：userDataPushButton_clicked
* 功能描述：添加的文件的按钮点击槽函数
* 输入参数：无
* 输出参数：无
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*
*************************************************/
void MessagePageStyle::userDataPushButton_clicked()
{
    /* sdk功能打点：文件上传 */
    GlobalData::SDKPointFileUpload();

    QSettings settingPath("./Setting.ini", QSettings::IniFormat);
    QString lastPath = settingPath.value("LastFilePath").toString();

    m_userUploadFileName= QFileDialog::getOpenFileName(this,tr("select file"),
                                                       lastPath,
                                                       "(*.gif *.jpg *.png *.pptx *.wps *.xlsx *.pdf *.txt *.docx)");

    if (m_userUploadFileName.isEmpty())
        return;
    //判断文件个数， 最多传五个附件
    uploadFile_afterButtonClicked();
}
/************************************************
* 函数名称：uploadFile_afterButtonClicked
* 功能描述：提交按钮点击后，根据文件数量进行对应动作
* 输入参数：无
* 输出参数：无
* 修改日期：2020.12.08
* 修改内容：
*   创建  HZH
*
*************************************************/
void MessagePageStyle::uploadFile_afterButtonClicked()
{
    if (m_uploadFileNameList.size() ==0)
    {
        qDebug() << "所有文件数量不到5个！" <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__;

        addFileInfoModel();
    }
    else if(m_uploadFileNameList.size() >= 5)
    {
        qDebug() << "所有文件数量超过5个！" <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__;
        return ;
    }
    else
    {
        qDebug() << "所有文件数量不到5个！" <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__;

        int file_diff_flags = 0;
        for (int fileNum = 0; fileNum < m_uploadFilePathList.size(); fileNum++) {
            //添加的文件已经添加过
            //Added files have been added.
            if (m_userUploadFileName.compare(m_uploadFilePathList.at(fileNum)) == 0)
                file_diff_flags++;
        }
        if (file_diff_flags == 0) {
            //添加附件框改变
            //Add attachment box changes
            addFileInfoModel();
        }
        if(m_uploadFileNameList.size()>=5)
        {
            ui->m_pUserDataPushButton->setEnabled(false);
        }
    }
}
/************************************************
* 函数名称：addFileInfoModel
* 功能描述：添加的文件的列表函数
* 输入参数：无
* 输出参数：无
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*
*************************************************/
void MessagePageStyle::addFileInfoModel()
{
    qDebug() << "添加文件到上传列表！" <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__;

    if (m_userUploadFileName.isEmpty())
    {
        commitButtonStyleSet();
        return;
    }

    int nIndex = m_userUploadFileName.lastIndexOf('/');
    QString file_name = m_userUploadFileName.mid(nIndex+1);
    QFileInfo info;
    QString file_size;
    info.setFile(m_userUploadFileName);

    file_size = QString::number((float)info.size()/(float)1024,'f',1) + "K";

    if((float)info.size()/(float)1000 > 1000)
        file_size = QString::number((float)info.size()/(float)1048576,'f',1) + "M";

    for (int i = 0; i < m_uploadFileNameList.size(); i++)
    {
        ui->FileListWidget->removeItemWidget(m_fileListWidgetItem[i]);
        delete m_fileListWidgetItem[i];
        m_fileListWidgetItem[i] = nullptr;
        delete m_fileWidget[i];
        m_fileWidget[i] = nullptr;
    }
    if (m_uploadFileNameList.size() < 5)
    {
        m_uploadFileNameList.append(file_name);
        m_uploadFileSizeList.append(file_size);
        m_uploadFilePathList.append(m_userUploadFileName);
    }

    update_add_file_window();
}
/************************************************
* 函数名称：update_add_file_window
* 功能描述：添加删除文件后更新列表函数
* 输入参数：无
* 输出参数：无
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*
*************************************************/
void MessagePageStyle::update_add_file_window()
{
    commitButtonStyleSet();

    if(m_uploadFileNameList.size() > 0)
    {
        ui->FileListWidget->show();
    }
    else
    {
        ui->FileListWidget->hide();
    }
    QString filename_labelstr;
    ui->FileListWidget->setFixedHeight(36 * (m_uploadFileNameList.size()) + 2);

    for (int filenum = 0; filenum < m_uploadFileNameList.size(); filenum++) {

        m_fileListWidgetItem[filenum] = new QListWidgetItem;

        m_fileListWidgetItem[filenum]->setSizeHint(QSize(616,36));
        m_fileWidget[filenum] = new FileItemInit(ui->FileListWidget);
        ui->FileListWidget->addItem(m_fileListWidgetItem[filenum]);
        ui->FileListWidget->setItemWidget(m_fileListWidgetItem[filenum],m_fileWidget[filenum]);

        filename_labelstr=m_uploadFileNameList.at(filenum);
        //如果文件过长，只显示前30个字符，后面省略
        //If the file is too long, show only the first 30 characters and omit the last
        if (m_uploadFileNameList.at(filenum).length() > 33) {
            filename_labelstr = m_uploadFileNameList.at(filenum).left(30) + "...";
        }

        m_fileWidget[filenum]->setFileNameLabelText(filename_labelstr);


        m_fileWidget[filenum]->setFileSizeLabelText(m_uploadFileSizeList.at(filenum));
        m_fileWidget[filenum]->changeFont(m_smallFont);
//        m_fileWidget[filenum]->getDelBtn()->setProperty("isImportant",true);
        connect( m_fileWidget[filenum]->getDelBtn(), SIGNAL(clicked()), this, SLOT(del_file_button_clicked()) );
    }
}

/************************************************
* 函数名称：del_file_button_clicked
* 功能描述：删除文件按钮点击槽函数
* 输入参数：无
* 输出参数：无
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*
*************************************************/
void MessagePageStyle::del_file_button_clicked()
{
    //返回发送信号的对象的指针
    //Returns a pointer to the object that sent the signal.
    QPushButton *btn = qobject_cast<QPushButton*>(QObject::sender());

    int listnum = m_uploadFileNameList.size();

    removeUploadFileNameListFile(btn);

    for (int i=0; i<listnum; i++) {
        delete m_fileListWidgetItem[i];
        delete m_fileWidget[i];
    }

    update_add_file_window();

    commitButtonStyleSet();
}
/************************************************
* 函数名称：removeUploadFileNameListFile
* 功能描述：点击listwidget中的del按钮，删除对应项
* 输入参数：QPushButton* btn 按钮指针
* 输出参数：无
* 修改日期：2020.12.08
* 修改内容：
*   创建  HZH
*
*************************************************/
void MessagePageStyle::removeUploadFileNameListFile(QPushButton* btn)
{
    if ( btn == m_fileWidget[0]->getDelBtn() )
    {
        m_uploadFileNameList.removeAt(0);
        m_uploadFileSizeList.removeAt(0);
        m_uploadFilePathList.removeAt(0);
        ui->m_pUserDataPushButton->setEnabled(true);
    }
    else if( btn == m_fileWidget[1]->getDelBtn() )
    {
        m_uploadFileNameList.removeAt(1);
        m_uploadFileSizeList.removeAt(1);
        m_uploadFilePathList.removeAt(1);
        ui->m_pUserDataPushButton->setEnabled(true);
    }
    else if( btn == m_fileWidget[2]->getDelBtn() )
    {
        m_uploadFileNameList.removeAt(2);
        m_uploadFileSizeList.removeAt(2);
        m_uploadFilePathList.removeAt(2);
        ui->m_pUserDataPushButton->setEnabled(true);
    }
    else if( btn == m_fileWidget[3]->getDelBtn() )
    {
        m_uploadFileNameList.removeAt(3);
        m_uploadFileSizeList.removeAt(3);
        m_uploadFilePathList.removeAt(3);
        ui->m_pUserDataPushButton->setEnabled(true);
    }
    else if( btn == m_fileWidget[4]->getDelBtn() )
    {
        m_uploadFileNameList.removeAt(4);
        m_uploadFileSizeList.removeAt(4);
        m_uploadFilePathList.removeAt(4);
        ui->m_pUserDataPushButton->setEnabled(true);

    }
    else
    {
        qDebug() << "函数异常错误！" <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__;
        return;
    }
}

/************************************************
* 函数名称：get_today_syslog
* 功能描述：截取今天的syslog
* 输入参数：无
* 输出参数：无
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*
*************************************************/
QByteArray MessagePageStyle::get_today_syslog()
{
    QDate date(QDate::currentDate());
    QList<QString> month_str = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
    QProcess process;
    QString shell ;
    shell.append("cat /var/log/syslog | grep ");
    shell.append("'");
    shell.append(month_str.at(date.month()-1));
    shell.append(" ");
    shell.append(QString::number(date.day()));
    shell.append("'");

    process.start(shell);
    process.waitForFinished();
    QByteArray output = process.readAllStandardOutput();

    return output;
}
/************************************************
* 函数名称：mailTextEditFoucusOut
* 功能描述：mailText被选中判断
* 输入参数：无
* 输出参数：无
* 修改日期：2020.12.19
* 修改内容：
*   创建  HZH
*
*************************************************/
void MessagePageStyle::mailTextEditFoucusOut()
{
    if("" == ui->m_pMailTextEdit->text())
    {
        ui->m_pMailFormatErr->hide();
        ui->m_pMailTextEdit->setState(kdk::Ordinary);
        m_isMailFormat = false;
    }
    else
    {
        m_mailText = ui->m_pMailTextEdit->text();

        QRegExp rx("^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+");
        int pos=0;
        QRegExpValidator v(rx, 0);
        if (2==v.validate(m_mailText,pos))
        {
            ui->m_pMailTextEdit->setState(kdk::LoginSuccess);
            ui->m_pMailFormatErr->hide();
            m_isMailFormat = true;

        }
        else
        {
            m_isMailFormat = false;
            ui->m_pMailFormatErr->show();
            ui->m_pMailTextEdit->setState(kdk::LoginFailed);
        }
    }

    commitButtonStyleSet();
}

/************************************************
* 函数名称：mailHostConnectResult
* 功能描述：e-mail host链接结果处理槽函数
* 输入参数：无
* 输出参数：无
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*
*************************************************/
void MessagePageStyle::mailHostConnectResult(int connectRes)
{
    if(int(SmtpErrType::SmtpOpSucc) != connectRes)
    {
        m_waitDialog->hide();

        m_failDialog->show_faillinfo(connectRes); //timeout
        m_failDialog->setModal(true);

        QPoint temp = QPoint(this->mapToGlobal(QPoint(0,0)).x() -90 + this->width()/2,this->mapToGlobal(QPoint(0,0)).y() + this->height()/2 -40);
        m_failDialog->move(temp - m_failDialog->rect().center());
        
        /* 适配kysdk的窗管 */
        kdk::UkuiStyleHelper::self()->removeHeader(m_failDialog);
        m_failDialog->show();

        m_pMailThread->quit();
        if(!m_pMailThread->wait(3000)) //Wait until it actually has terminated (max. 3 sec)
        {
            m_pMailThread->terminate(); //Thread didn't exit in time, probably deadlocked, terminate it!
            m_pMailThread->wait(); //We have to wait again here!
        }

        m_pMailThread->deleteLater();

        m_eMail = new SmtpMailClient();
        m_pMailThread = new QThread();
        m_eMail->moveToThread(m_pMailThread);
        connect(m_pMailThread, &QThread::finished, m_eMail, &QObject::deleteLater,Qt::UniqueConnection);//挂载
        connect(this,&MessagePageStyle::connectToHost, m_eMail,&SmtpMailClient::connectToHost,Qt::UniqueConnection);
        connect(m_eMail,&SmtpMailClient::hostConnectResult,this,&MessagePageStyle::mailHostConnectResult,Qt::UniqueConnection);
        connect(this,&MessagePageStyle::sendMail, m_eMail,&SmtpMailClient::sendMail,Qt::UniqueConnection);
        connect(m_eMail,&SmtpMailClient::mailSendResult,this,&MessagePageStyle::mailSendResult,Qt::UniqueConnection);
        m_pMailThread->start();

        QTimer::singleShot(3000, [=](){
            m_failDialog->hide();
            set_all_enable_after_submit();
        });
    }
    else
    {
        QTimer::singleShot(3000, [=](){
            emit sendMail(m_messageStruct);
        });
    }
}
/************************************************
* 函数名称：mailSendResult
* 功能描述：e-mail send结果处理槽函数
* 输入参数：无
* 输出参数：无
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*
*************************************************/
void MessagePageStyle::mailSendResult(int sendRes)
{
    if(int(SmtpErrType::SmtpOpSucc) != sendRes)
    {
        m_waitDialog->hide();
        m_failDialog->show_faillinfo(sendRes); //timeout
        m_failDialog->setModal(true);

        QPoint temp = QPoint(this->mapToGlobal(QPoint(0,0)).x() -90 + this->width()/2,this->mapToGlobal(QPoint(0,0)).y() + this->height()/2 -40);
        m_failDialog->move(temp - m_failDialog->rect().center());

        m_pMailThread->quit();
        if(!m_pMailThread->wait(3000))
        {
            m_pMailThread->terminate();
            m_pMailThread->wait();
        }

        m_pMailThread->deleteLater();

        m_eMail = new SmtpMailClient();
        m_pMailThread = new QThread();
        m_eMail->moveToThread(m_pMailThread);
        connect(m_pMailThread, &QThread::finished, m_eMail, &QObject::deleteLater,Qt::UniqueConnection);//挂载
        connect(this,&MessagePageStyle::connectToHost, m_eMail,&SmtpMailClient::connectToHost,Qt::UniqueConnection);
        connect(m_eMail,&SmtpMailClient::hostConnectResult,this,&MessagePageStyle::mailHostConnectResult,Qt::UniqueConnection);
        connect(this,&MessagePageStyle::sendMail, m_eMail,&SmtpMailClient::sendMail,Qt::UniqueConnection);
        connect(m_eMail,&SmtpMailClient::mailSendResult,this,&MessagePageStyle::mailSendResult,Qt::UniqueConnection);
        m_pMailThread->start();

        m_failDialog->setModal(true);

        /* 适配kysdk的窗管 */
        kdk::UkuiStyleHelper::self()->removeHeader(m_failDialog);
        m_failDialog->show();

        QTimer::singleShot(3000, [=](){
            m_failDialog->hide();
            set_all_enable_after_submit();
        });
    }
    else
    {
        m_waitDialog->hide();

        QPoint temp = QPoint(this->mapToGlobal(QPoint(0,0)).x() -90 + this->width()/2,this->mapToGlobal(QPoint(0,0)).y() + this->height()/2 -40);
        m_successDialog->move(temp - m_successDialog->rect().center());

        m_pMailThread->quit();
        if(!m_pMailThread->wait(3000))
        {
            m_pMailThread->terminate();
            m_pMailThread->wait();
        }

        m_pMailThread->deleteLater();

        m_eMail = new SmtpMailClient();
        m_pMailThread = new QThread();
        m_eMail->moveToThread(m_pMailThread);
        connect(m_pMailThread, &QThread::finished, m_eMail, &QObject::deleteLater,Qt::UniqueConnection);//挂载
        connect(this,&MessagePageStyle::connectToHost, m_eMail,&SmtpMailClient::connectToHost,Qt::UniqueConnection);
        connect(m_eMail,&SmtpMailClient::hostConnectResult,this,&MessagePageStyle::mailHostConnectResult,Qt::UniqueConnection);
        connect(this,&MessagePageStyle::sendMail, m_eMail,&SmtpMailClient::sendMail,Qt::UniqueConnection);
        connect(m_eMail,&SmtpMailClient::mailSendResult,this,&MessagePageStyle::mailSendResult,Qt::UniqueConnection);
        m_pMailThread->start();

        m_successDialog->setModal(true);

        /* 适配kysdk的窗管 */
        // ::kabase::WindowManage::removeHeader(m_successDialog);
        kdk::UkuiStyleHelper::self()->removeHeader(m_successDialog);

        m_successDialog->show();

        QTimer::singleShot(3000, [=](){

            set_all_enable_after_submit();
            on_resetButton_clicked();
            m_successDialog->hide();
            m_submittingTimer->start(30000);
        });
    }
}
/************************************************
* 函数名称：getSysteminfo
* 功能描述：获取本机系统信息
* 输入参数：无
* 输出参数：无
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*
*************************************************/
void MessagePageStyle::getSysteminfo()
{
    //获取系统信息
    //Access to system information
    //1.获取系统版本
    //Get the system version
    getSysVersion();
    //2.获取桌面环境信息
    //Access to desktop environment information
    getDesktopInfo();
    //3.获取编码格式
    //Get the coding format
    getCodingFormat();
}
/************************************************
* 函数名称：getCodingFormat
* 功能描述：获取系统信息的语言格式信息
* 输入参数：无
* 输出参数：无
* 修改日期：2020.12.08
* 修改内容：
*   创建  HZH
*
*************************************************/
void MessagePageStyle::getCodingFormat()
{
    string encoding_info = " ";
    char *encoding = getenv("LANG");
    char *emcoding_2;
    emcoding_2 = (char *)malloc(8);
    if(NULL == emcoding_2)
    {
        qDebug() << "emcoding_2申请内存失败！" <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__;
        return;
    }
    if (encoding == NULL) {
        QString locale = QLocale::system().name();
        memset(emcoding_2, '\0', sizeof(emcoding_2));
        if (locale == "en_US")
        {
            strncpy(emcoding_2, "en_US", sizeof(emcoding_2));
        }
        else if (locale == "zh_CN")
        {
            strncpy(emcoding_2, "zh_CN", sizeof(emcoding_2));
        }
        else if (locale == "bo_CN")
        {
            strncpy(emcoding_2, "bo_CN", sizeof(emcoding_2));
        }
        encoding = emcoding_2;
    }
    encoding_info.append(encoding);
    m_sendEncodingInfo.append(encoding);
    m_encodingInfoStr = QString::fromStdString(encoding_info);
    if(m_encodingInfoStr.contains(".")){
        QStringList list = m_encodingInfoStr.split(".");
        m_labelLanguage_2->setText(list.at(0));

        if(m_sendEncodingInfo.contains(".")){
            QStringList list2 = m_sendEncodingInfo.split(".");
            m_sendEncodingInfo.clear();
            m_sendEncodingInfo.append(list2.at(0));
        }

    }
    else
    {
        m_labelLanguage_2->setText(m_encodingInfoStr);
    }
    if(emcoding_2 != NULL)
    {
        free(emcoding_2);
    }
}

/************************************************
* 函数名称：getSysVersion
* 功能描述：获取系统版本信息
* 输入参数：无
* 输出参数：无
* 修改日期：2020.12.08
* 修改内容：
*   创建  HZH
*
*************************************************/
void MessagePageStyle::getSysVersion()
{
    QString os_info = " ";
    QString system_info;
    QString system_name;

    string s;
    ifstream fp("/etc/lsb-release");
    if (!fp) {
        system_info = "None";
    } else {
        while (getline(fp,s)) {
            string::size_type idx;
            idx = s.find("=");
            if (idx == string::npos) {
                //不存在
            } else {
                string str2 = s.substr(0,idx);

                if(str2 == "DISTRIB_DESCRIPTION")
                {
                    system_name = QString::fromStdString(s.substr(20));
                }
            }
        }

    }
    m_sendOsInfo = (system_name).replace("\"", "");

    m_systemInfoStr = os_info + m_sendOsInfo;

    m_labelSystemVersion_2->setText(m_systemInfoStr);
}

/************************************************
* 函数名称：getDesktopInfo
* 功能描述：获取桌面版本信息
* 输入参数：无
* 输出参数：无
* 修改日期：2020.12.08
* 修改内容：
*   创建  HZH
*
*************************************************/
void MessagePageStyle::getDesktopInfo()
{
    QString desktop_info = " ";
    char * desktop = getenv("DESKTOP_SESSION");
    if (desktop == NULL)
    {
        desktop_info.append("unknown");
    }
    desktop_info.append(desktop);
    m_sendDekstopInfo.append(desktop);
    m_desktopInfoStr = desktop_info;
    m_labelDesktopVersion_2->setText(m_desktopInfoStr);
}
/************************************************
* 函数名称：systeminfo_show
* 功能描述：显示本机系统信息
* 输入参数：无
* 输出参数：无
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*
*************************************************/
void MessagePageStyle::systeminfo_show(QPointF pt)
{
    Q_UNUSED(pt);
    this->update();


//    m_verticalWidget->move(QPoint(218,442));

    m_labelSystemVersion_1->adjustSize();
    m_labelSystemVersion_2->adjustSize();
    m_labelDesktopVersion_1->adjustSize();
    m_labelDesktopVersion_2->adjustSize();
    m_labelLanguage_1->adjustSize();
    m_labelLanguage_2->adjustSize();

    m_verticalWidget->hide();
    m_verticalWidget->show();

    m_verticalWidget->adjustSize();
    QPoint temp = QPoint(ui->m_showInfoButton->mapToParent(QPoint(0,0)).x() - 5,
                         ui->m_showInfoButton->mapToParent(QPoint(0,0)).y() - m_verticalWidget->height() - 5);
    m_verticalWidget->move(temp);

}
/************************************************
* 函数名称：systeminfo_hide
* 功能描述：隐藏本机系统信息
* 输入参数：无
* 输出参数：无
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*
*************************************************/
void MessagePageStyle::systeminfo_hide()
{
    m_verticalWidget->hide();
}

void MessagePageStyle::changeFont(QFont curFont)
{
    ui->m_pTitleOfAsk->setFont(curFont);
    ui->m_pStyleOfAsk->setFont(curFont);
    ui->m_pStyleOfAskCombobox->setFont(curFont);

    ui->m_pContentTextEdit->setFont(curFont);
    QString contentTextEditSheet="QTextEdit#ContentTextEdit{background-color:palette(Button);border-radius:6px;}"
                                 "QTextEdit#ContentTextEdit:Hover{background-color:palette(Button);border-radius:6px;}"
                                 "QTextEdit#ContentTextEdit:Focus{background-color:palette(Base);border-radius:6px;border:2px solid palette(Highlight)}";
    ui->m_pContentTextEdit->setStyleSheet(contentTextEditSheet);
    ui->m_pDetailTextLetterLimit->setFont(curFont);
    ui->m_pUserData->setFont(curFont);
    ui->m_pUserDataPushButton->setFont(curFont);
    allFileSizeLargerThan10M();

    ui->m_pLog->setFont(curFont);
    ui->m_pTrueSyslogRadioButton->setFont(curFont);
    ui->m_pFalseSyslogRadioButton->setFont(curFont);
    ui->m_pMail->setFont(curFont);
    ui->m_pMailTextEdit->setFont(curFont);
    ui->m_pMailFormatErr->setStyleSheet(QString::fromUtf8("color: rgba(237, 100, 100, 1);"));
    ui->m_pMailFormatErr->setFont(curFont);
    ui->m_pTel->setFont(curFont);
    ui->m_pName->setFont(curFont);
    ui->m_pNameTextEdit->setFont(curFont);
    ui->m_pTelTextEdit->setFont(curFont);
    ui->m_pUserPermission->setFont(curFont);
    ui->m_showInfoButton->setFont(curFont);
    ui->commitButton->setFont(curFont);
    ui->resetButton->setFont(curFont);

    m_smallFont = GlobalData::getInstance()->getFontSize12px();
    
    ui->m_pUserDataLimit->setFont(m_smallFont);
    ui->m_pUserDataLimit_2->setFont(m_smallFont);
    m_labelLanguage_1->setFont(m_smallFont);
    m_labelDesktopVersion_1->setFont(m_smallFont);
    m_labelSystemVersion_1->setFont(m_smallFont);
    m_labelLanguage_2->setFont(m_smallFont);
    m_labelSystemVersion_2->setFont(m_smallFont);
    m_labelDesktopVersion_2->setFont(m_smallFont);

    for (int filenum = 0; filenum < m_uploadFileNameList.size(); filenum++) {
        m_fileWidget[filenum]->changeFont(m_smallFont);
    }

}

void MessagePageStyle::changePageForTheme(const QString& str)
{
    m_currentTheme = str;
    if(m_uploadFileNameList.size() > 0)
    {
        ui->FileListWidget->show();
    }
}
